﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

//http://social.msdn.microsoft.com/Forums/en/vbpowerpacks/thread/87c15a18-dd30-4ebd-9775-3777c3225168
using SpeechLib;

namespace TTSPlayer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnRead_Click(object sender, EventArgs e)
        {
            // show which the current sentence, we need to show it in a textbox
            MessageBox.Show(_allText[_currentIndex]);

            int tmpSpeed = Convert.ToInt32(numericspeed.Value);
            int tmpVol = Convert.ToInt32(numericvolume.Value);

            SpVoice voice = new SpVoice();
            voice.Voice = voice.GetVoices("", "").Item(comboBox1.SelectedIndex);
            voice.Rate = tmpSpeed;
            voice.Volume = tmpVol;

            voice.Speak(txtMain.Text, SpeechVoiceSpeakFlags.SVSFDefault);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            numericspeed.Maximum = 50;
            numericspeed.Minimum = -50;
            numericspeed.Value = 0;
            numericvolume.Maximum = 200;
            numericvolume.Minimum = 0;
            numericvolume.Value = 50;
            SpVoice voice = new SpVoice();

            foreach (SpeechLib.ISpeechObjectToken token in voice.GetVoices("", ""))
            {
                comboBox1.Items.Add(token.GetDescription(0));
            }

            comboBox1.SelectedIndex = 0;
        }

        private void numericUpDown2_ValueChanged(object sender, EventArgs e)
        {

        }

        // dedicate the active index of the string array
        private int _currentIndex = 0;

        // the whole string array
        private string[] _allText = new string[] {"您好,我是第一个句子","我是语音播放器","暂时没有其它句子了" };
    }
}
